import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isLogin: false,
    isAdminLogin: false,
    search: {
      keyword: "",
      option: "",
      isAdvance: false,
    }
  },
  mutations: {
    login(state) {
      state.isLogin = true;
      // var user = {
      //     username: window.sessionStorage.getItem("username"),
      //     uid: window.sessionStorage.getItem('uid')
      // }
      // localStorage.setItem("LoginState", JSON.stringify(user));
    },
    adminLogin(state) {
      state.isAdminLogin = true;
    },
    logout(state) {
      window.sessionStorage.removeItem("session_id");
      window.sessionStorage.removeItem("user_id");
      window.sessionStorage.removeItem("user_name");
      window.sessionStorage.removeItem("user_avatar");
      window.sessionStorage.removeItem("portal_id");
      state.isLogin = false;
      state.isAdminLogin = false;
    },
    search(state, data) {
      state.search.keyword = data.keyword;
      state.search.option = data.option;
      state.search.isAdvance = data.isAdvance;
    }
  },
  actions: {
  },
  modules: {
  }
})
